var t = getApp(), e = t.requirejs('core');
Page({
    data: {
        active: 1,
        value: '',
        list: [
            {id: 1, num: 100},
            {id: 2, num: 200},
            {id: 3, num: 300},
            {id: 4, num: 500},
            {id: 5, num: 1000},
        ],
        data: {},
        id: ''
    },
    onLoad(s) {
        this.setData(s);
        e.get('syt/card/get_info', s, res => {
            console.log(res);
            this.setData({
                data: res,
                list:res.newgive
            })
        })
    },
    // 充值
    renew() {
        let _this = this, _data = _this.data, money;
        // 已选中的充值金额
        if(_data.active != 'custom') {
            for (const item of _data.list) {
                if(item.id == _data.active) {
                    money = item.num
                }
            }
            console.log(money);
        } else {
            // 自定义充值金额
            if(!_data.value) {
                wx.showToast({
                    title: "请输入自定义金额",
                    icon: 'none'
                });
                return
            }
            money = _data.value;
        }
        wx.showLoading({
            title: '订单生成中...',
        })
      
        e.get("syt.card.pay", {money:money, id: _data.id}, res => {
            wx.hideLoading({
                success: (resa) => {
                    wx.navigateTo({
                        url: '/project/member/pay?id=' + res.id,
                    })
                },
            })
            
        })
    },
    // 切换
    change(s) {
        let active = s.currentTarget.dataset.id;
        this.setData({active})
    },
    // 绑定其它金额
    bindother(s) {
        let value = s.detail.value;
        this.setData({value})
    }
})